package com.efounder.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.efounder.activity.MallOrderDetailActivity;
import com.efounder.activity.MallSelectionPayNoAliWxActivity;
import com.efounder.activity.MallVirtualProductSelectionPayActivity;
import com.efounder.activity.MallWinTreasureDetailsActivity;
import com.efounder.activity.ProductDetailsActivity;
import com.efounder.activity.SelectionPayActivity;
import com.efounder.bean.OrderBody;
import com.efounder.bean.OrderFoot;
import com.efounder.bean.OrderHead;
import com.efounder.bean.OrderStoreInfo;
import com.efounder.bean.UpdateCartBadgeEvent;
import com.efounder.constant.EnvironmentVariable;
import com.efounder.mobilemall.R;
import com.efounder.util.ToastUtil;
import com.efounder.utils.MallRequestUtil;
import com.efounder.utils.ResStringUtil;
import com.pansoft.openplanet.util.TCMathUtil;
import com.utilcode.util.ToastUtils;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static com.efounder.fragment.MallOrderFragment.ORDER_TYPE_NEW_VIRTUAL;
import static com.efounder.fragment.MallOrderFragment.ORDER_TYPE_TREASURE;
import static com.efounder.fragment.MallOrderFragment.ORDER_TYPE_VIRTUAL;
import static com.efounder.utils.MallRequestUtil.CART_ADD_OR_DELETE_URL;

/**
 * Created by will on 18-2-7.
 * 商城订单适配器
 */

public class OrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private static final int VIEW_TYPE_HEADER = 0;
    private static final int VIEW_TYPE_BODY = 1;
    private static final int VIEW_TYPE_FOOTER = 2;
    private static final int VIEW_TYPE_STORE_INFO = 3;
    //待支付
    public static final String MALL_NEED_PAY = "0";
    //待发货
    public static final String MALL_NEED_SEND_GOOD = "1";
    //待收货
    public static final String MALL_NEED_RECEIVE = "4";
    //待评价
    public static final String MALL_NEED_COMMENT = "5";
    //订单关闭
    public static final String MALL_ORDER_CLOSE = "8";
    //退款中
    public static final String MALL_REFUND = "2";
    //已完成
    public static final String MALL_COMPLETED = "6";
    //已取消
    public static final String MALL_CANCEL = "7";
    //已删除
    public static final String MALL_DELETE = "9";
    //夺宝付款失败
    public static final String SNATCH_PAY_FAIL = "-1";
    //夺宝付款成功
    public static final String SNATCH_PAY_SUCCESSL = "-2";
    //夺宝已开奖
    public static final String SNATCH_WIN = "-3";
    // 夺宝支付中
    public static final String  SNATCH_PAYING = "-4";


    private Context mContext;
    private List<Object> orderList;
    private OnOrderAdapterListener onOrderAdapterListener;

    public OrderAdapter(Context mContext, List<Object> orderList) {
        this.mContext = mContext;
        this.orderList = orderList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        if (viewType == VIEW_TYPE_HEADER) {
            view = LayoutInflater.from(mContext).inflate(R.layout.layout_order_item_header, parent, false);
            return new OrderHeaderHolder(view);
        } else if (viewType == VIEW_TYPE_BODY) {
            view = LayoutInflater.from(mContext).inflate(R.layout.layout_order_item_body, parent, false);
            return new OrderViewHolder(view);
        } else if (viewType == VIEW_TYPE_FOOTER) {
            view = LayoutInflater.from(mContext).inflate(R.layout.layout_order_item_footer, parent, false);
            return new OrderFooterHolder(view);
        } /*else if (viewType == VIEW_TYPE_STORE_INFO) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_store_info_title, parent, false);
            return new StoreInfoTitleHolder(view);
        }*/
        return null;
    }

    @SuppressLint("StringFormatMatches")
    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof OrderHeaderHolder) {
            ((OrderHeaderHolder) holder).tvOrderDate.setText(((OrderHead) orderList.get(position)).getOrderDate());
            String orderStatus = ((OrderHead) orderList.get(position)).getOrderStatus();
            if (orderStatus.equals(MALL_NEED_PAY)) {
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_need_pay);
                ((OrderHeaderHolder) holder).order_iv_delete.setVisibility(View.VISIBLE);
            } else if (orderStatus.equals(MALL_NEED_SEND_GOOD)) {
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_need_send_good);
                ((OrderHeaderHolder) holder).order_iv_delete.setVisibility(View.GONE);
            } else if (orderStatus.equals(MALL_NEED_RECEIVE)) {
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_need_receive);
                ((OrderHeaderHolder) holder).order_iv_delete.setVisibility(View.GONE);
            } else if (orderStatus.equals(MALL_NEED_COMMENT)) {
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_need_assess);
                ((OrderHeaderHolder) holder).order_iv_delete.setVisibility(View.VISIBLE);

            } else if (orderStatus.equals(MALL_ORDER_CLOSE)) {
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_order_off);
                ((OrderHeaderHolder) holder).order_iv_delete.setVisibility(View.VISIBLE);
            } else if (MALL_REFUND.equals(orderStatus)) {//退款中
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_refund);
                ((OrderHeaderHolder) holder).order_iv_delete.setVisibility(View.GONE);
            } else if (MALL_COMPLETED.equals(orderStatus)) {//已完成
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_done);
                ((OrderHeaderHolder) holder).order_iv_delete.setVisibility(View.VISIBLE);

            } else if (MALL_CANCEL.equals(orderStatus)) {//已取消
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_cancle);
                ((OrderHeaderHolder) holder).order_iv_delete.setVisibility(View.VISIBLE);

            } else if (MALL_DELETE.equals(orderStatus)) {//已删除
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_delete);
                ((OrderHeaderHolder) holder).order_iv_delete.setVisibility(View.GONE);

                //夺宝支付失败
            } else if (SNATCH_PAY_FAIL.equals(orderStatus)) {
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_order_snatch_pay_fail);
                //夺宝支付成功
            } else if (SNATCH_PAY_SUCCESSL.equals(orderStatus)) {
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_order_snatch_pay_success);
                //夺宝已中奖
            } else if (SNATCH_WIN.equals(orderStatus)) {
                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_order_snatch_pay_win);
            } else if (SNATCH_PAYING.equals(orderStatus)) {

                ((OrderHeaderHolder) holder).tvOrderStatus.setText(R.string.mail_order_snatch_paying);
            }

            ((OrderHeaderHolder) holder).tv_store_name.setText(((OrderHead) orderList.get(position)).getShopName());
            Glide.with(mContext)
                    .load(((OrderHead) orderList.get(position)).getShopBrandlog())
                    .apply(new RequestOptions().fitCenter()
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .skipMemoryCache(false))
                    .into(((OrderHeaderHolder) holder).iv_warehouse);

            ((OrderHeaderHolder) holder).llDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //todo
                }
            });
        } else if (holder instanceof OrderViewHolder) {
            ((OrderViewHolder) holder).tvTitle.setText(((OrderBody) orderList.get(position)).getOrderTitle());
            ((OrderViewHolder) holder).tvNum.setText("x" + ((OrderBody) orderList.get(position)).getOrderNum());
            ((OrderViewHolder) holder).tvModel.setText(((OrderBody) orderList.get(position)).getOrderModel());
            ((OrderViewHolder) holder).tvPrice.setText(((OrderBody) orderList.get(position)).getPriceUnit() + " " + TCMathUtil.retainAsignDecimalsWithZero(((OrderBody) orderList.get(position)).getOrderPrice(), 2));
            if (ResStringUtil.getString(R.string.mall_win_treasure).equals(((OrderBody) orderList.get(position)).getOrderMark())) {
                ((OrderViewHolder) holder).tvMark.setVisibility(View.VISIBLE);
                ((OrderViewHolder) holder).tvMark.setText(((OrderBody) orderList.get(position)).getOrderMark());
            } else {
                ((OrderViewHolder) holder).tvMark.setVisibility(View.GONE);
            }
            Glide.with(mContext)
                    .load(((OrderBody) orderList.get(position)).getOrderImg())
                    .apply(new RequestOptions().fitCenter()
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .skipMemoryCache(false))
                    .into(((OrderViewHolder) holder).ivImg);
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mContext, MallOrderDetailActivity.class);
                    intent.putExtra("orderBh", ((OrderBody) orderList.get(holder.getAdapterPosition())).getOrderBh());
                    mContext.startActivity(intent);
                }
            });
        } else if (holder instanceof OrderFooterHolder) {
            ((OrderFooterHolder) holder).tvTotalPrice.setText(((OrderFoot) orderList.get(position)).getPriceUnit() + " " + TCMathUtil.retainAsignDecimalsWithZero(((OrderFoot) orderList.get(position)).getAfterDiscountTotalPrice(), 2));
            ((OrderFooterHolder) holder).tvTotalNum.setText(mContext.getResources().getString(R.string.mall_order_total_item,((OrderFoot) orderList.get(position)).getOrderTotalNum() ));
            ((OrderFooterHolder) holder).tvRebuy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //普通商品添加购物车，虚拟商品跳转商品详情
                    if(ORDER_TYPE_VIRTUAL == ((OrderFoot)orderList.get(position)).getOrderType()||ORDER_TYPE_NEW_VIRTUAL == ((OrderFoot)orderList.get(position)).getOrderType()){
                        Intent intent = new Intent(mContext, ProductDetailsActivity.class);
                        intent.putExtra("goodbh", ((OrderFoot)orderList.get(position)).getGoodsId());
                        mContext.startActivity(intent);
                    }else {
                        addCart(holder);
                    }
                }
            });
            final String orderStatus = ((OrderFoot) orderList.get(position)).getOrderStatus();
            if (orderStatus.equals(MALL_NEED_PAY) || orderStatus.equals(MALL_CANCEL) ||
                    orderStatus.equals(MALL_ORDER_CLOSE)) {
                ((OrderFooterHolder) holder).tvTotalText.setText(R.string.mail__layout_should_pay_money);
            } else {
                ((OrderFooterHolder) holder).tvTotalText.setText(R.string.mall_real_pay_money);
            }
            //控制footer布局按钮的显示和隐藏
            setFooterButtonIsVisable(orderStatus,holder,position);

            ((OrderFooterHolder) holder).tvCheckout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String orderTitle = "";
                    for (OrderBody cartItem : ((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderBodies()) {
                        orderTitle = orderTitle.concat(cartItem.getOrderTitle() + " ");
                    }
                    OrderFoot orderFoot = ((OrderFoot) orderList.get(holder.getAdapterPosition()));
                    ArrayList<String> orderIds = new ArrayList<>();
                    orderIds.add(orderFoot.getOrderBh());
                    if (((OrderFoot) orderList.get(position)).getOrderType() == ORDER_TYPE_TREASURE) {
                        //夺宝支付页面跳转
                        MallSelectionPayNoAliWxActivity.start(mContext, orderIds, ((OrderFoot) orderList.get(position)).getGoodsId()
                                , ((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderTotalPrice() + "");
                    }else if(((OrderFoot) orderList.get(position)).getOrderType() == ORDER_TYPE_VIRTUAL){
                        //虚拟商品支付页面跳转
                        MallVirtualProductSelectionPayActivity.start(mContext, orderIds, orderTitle  ,((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderTotalPrice() + ""
                               );
                    } else {
                        //普通商品跳支付
                        Intent intent = new Intent(mContext, SelectionPayActivity.class);
                        intent.putStringArrayListExtra("orderId", orderIds);
                        intent.putExtra("orderAmount", ((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderTotalPrice() + "");
                        intent.putExtra("orderTitle", orderTitle);
                        mContext.startActivity(intent);
                    }
                }
            });
            ((OrderFooterHolder) holder).tv_cancle_order.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onOrderAdapterListener != null) {
                        onOrderAdapterListener.cancleOrder(holder.getAdapterPosition(), ((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderBodies());
                    }
                }
            });
            ((OrderFooterHolder) holder).tvConfirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onOrderAdapterListener != null) {
                        onOrderAdapterListener.onConfirmOrder(holder.getAdapterPosition(), ((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderBodies());
                    }
                }
            });
            ((OrderFooterHolder) holder).tvGotoComment.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onOrderAdapterListener != null) {
                        onOrderAdapterListener.onComment(holder.getAdapterPosition(), ((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderBodies());
                    }
                }
            });
            ((OrderFooterHolder) holder).tvTrace.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, MallOrderDetailActivity.class);
                    intent.putExtra("orderBh", ((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderBh());
                    mContext.startActivity(intent);
                }
            });
            /**
             * 跳转夺宝详情界面
             */
            ((OrderFooterHolder) holder).tvSnatchDetails.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MallWinTreasureDetailsActivity.start(mContext, ((OrderFoot) orderList.get(position)).getGoodsId(),orderStatus);
                }
            });
            ((OrderFooterHolder) holder).tvDeleteOrder.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onOrderAdapterListener != null) {
                        onOrderAdapterListener.onDeleteOrder(holder.getAdapterPosition(), ((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderBodies());
                    }
                }
            });
        } else if (holder instanceof StoreInfoTitleHolder) {
            // 店铺信息
            OrderStoreInfo orderStoreInfo = (OrderStoreInfo) orderList.get(position);
            ((StoreInfoTitleHolder) holder).tv_store_name.setText(orderStoreInfo.getShopName());
            Glide.with(mContext)
                    .load(orderStoreInfo.getShopBrandlog())
                    .apply(new RequestOptions().fitCenter()
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .skipMemoryCache(false))
                    .into(((StoreInfoTitleHolder) holder).iv_warehouse);

        }
    }

    /**
     * 添加购物车
     * @param holder
     */
    private void addCart(RecyclerView.ViewHolder holder) {
        HashMap<String, String> map = new HashMap<>();
        map.put("userId", EnvironmentVariable.getUserName());
        try {
            JSONArray jsonArray = new JSONArray();
            for (OrderBody orderBody : ((OrderFoot) orderList.get(holder.getAdapterPosition())).getOrderBodies()) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("goodbh", orderBody.getGoodBh());
                jsonObject.put("goodNum", orderBody.getOrderNum());
                jsonObject.put("skuId", orderBody.getSkuId());
                jsonArray.put(jsonObject);
            }
            map.put("goods", jsonArray.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        MallRequestUtil.getRequest(mContext.getClass().getSimpleName(), CART_ADD_OR_DELETE_URL, map, new MallRequestUtil.MallRequestCallback() {
            @Override
            public void onSuccess(String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    if ("success".equals(jsonObject.optString("result"))) {
                        if (onOrderAdapterListener != null) {
                            onOrderAdapterListener.onRebuy();
                        }
                        EventBus.getDefault().post(new UpdateCartBadgeEvent());
                    } else if ("fail".equals(jsonObject.optString("result"))) {
                        ToastUtil.showToastCenter(jsonObject.optString("msg"));
                    } else {
                        ToastUtil.showToastCenter(mContext.getResources().getString(R.string.mail_join_car_fail));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFail(String error) {
                ToastUtils.showShort(R.string.mail_join_car_fail);
            }
        });

    }

    /**
     * 控制footer布局按钮的显示和隐藏
     * @param orderStatus
     * @param holder
     * @param position
     */
    private void setFooterButtonIsVisable(String orderStatus, RecyclerView.ViewHolder holder,int position) {
        if (orderStatus.equals(MALL_NEED_PAY)) {
            //("待付款");
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
        } else if (orderStatus.equals(MALL_NEED_SEND_GOOD)) {
            //("待发货");
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
        } else if (orderStatus.equals(MALL_NEED_RECEIVE)) {
            //("待收货");
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
//            }else if(((OrderFoot) orderList.get(position)).getOrderStatus().equals("5")){
//                ((OrderHeaderHolder) holder).tvOrderStatus.setText("待评论");
        } else if (orderStatus.equals(MALL_ORDER_CLOSE)) {
            //("订单关闭");
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.VISIBLE);
        } else if (MALL_REFUND.equals(orderStatus)) {//退款中
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
        } else if (MALL_COMPLETED.equals(orderStatus)) {//已完成
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
            //如果是虚拟商品   查看物流按钮隐藏
            if(((OrderFoot) orderList.get(position)).getOrderType() == ORDER_TYPE_VIRTUAL || ((OrderFoot) orderList.get(position)).getOrderType() == ORDER_TYPE_NEW_VIRTUAL){
                ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            }
        } else if (MALL_CANCEL.equals(orderStatus)) {//已取消
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.VISIBLE);
        } else if (MALL_DELETE.equals(orderStatus)) {//已删除
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
        } else if (MALL_NEED_COMMENT.equals(orderStatus)) {//待评价
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
            //如果是虚拟商品   查看物流按钮隐藏
            if(((OrderFoot) orderList.get(position)).getOrderType() == ORDER_TYPE_VIRTUAL|| ((OrderFoot) orderList.get(position)).getOrderType() == ORDER_TYPE_NEW_VIRTUAL){
                ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            }
            //夺宝支付失败
        } else if (SNATCH_PAY_FAIL.equals(orderStatus)) {
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.VISIBLE);
            //夺宝支付成功
        } else if (SNATCH_PAY_SUCCESSL.equals(orderStatus)) {
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
            //夺宝已中奖
        } else if (SNATCH_WIN.equals(orderStatus)) {
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.VISIBLE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
            //夺宝正在支付中
        } else if (SNATCH_PAYING.equals(orderStatus)) {
            ((OrderFooterHolder) holder).tvTrace.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvSnatchDetails.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvConfirm.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvCheckout.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tv_cancle_order.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvRebuy.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvGotoComment.setVisibility(View.GONE);
            ((OrderFooterHolder) holder).tvDeleteOrder.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemViewType(int position) {
        if (orderList.get(position) instanceof OrderHead) {
            return VIEW_TYPE_HEADER;
        } else if (orderList.get(position) instanceof OrderBody) {
            return VIEW_TYPE_BODY;
       /* } else if (orderList.get(position) instanceof OrderStoreInfo) {
            return VIEW_TYPE_STORE_INFO;*/
        } else if(orderList.get(position) instanceof OrderFoot){
            return VIEW_TYPE_FOOTER;
        }
        return 0;
    }

    @Override
    public int getItemCount() {
        return orderList.size();
    }

    class OrderViewHolder extends RecyclerView.ViewHolder {
        TextView tvTitle, tvPrice, tvNum, tvModel, tvMark;
        ImageView ivImg;

        public OrderViewHolder(View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tv_item_title);
            tvPrice = itemView.findViewById(R.id.tv_item_price);
            tvModel = itemView.findViewById(R.id.tv_item_desc);
            tvNum = itemView.findViewById(R.id.item_count);
            ivImg = itemView.findViewById(R.id.id_iv_logo);
            tvMark = itemView.findViewById(R.id.tv_good_mark);
        }
    }

    class OrderHeaderHolder extends RecyclerView.ViewHolder {
        TextView tvOrderDate, tvOrderStatus;
        LinearLayout llDelete;
        ImageView order_iv_delete;
        ImageView iv_warehouse;
        TextView tv_store_name;
        public OrderHeaderHolder(View itemView) {
            super(itemView);
            tvOrderDate = itemView.findViewById(R.id.tv_order_date);
            tvOrderStatus = itemView.findViewById(R.id.tv_order_status);
            llDelete = itemView.findViewById(R.id.ll_delete);
            order_iv_delete = itemView.findViewById(R.id.order_iv_delete);
            iv_warehouse = itemView.findViewById(R.id.iv_warehouse);
            tv_store_name = itemView.findViewById(R.id.tv_store_name);
        }
    }

    class StoreInfoTitleHolder extends RecyclerView.ViewHolder {
        ImageView iv_warehouse;
        TextView tv_store_name;

        public StoreInfoTitleHolder(View itemView) {
            super(itemView);
            iv_warehouse = itemView.findViewById(R.id.iv_warehouse);
            tv_store_name = itemView.findViewById(R.id.tv_store_name);
        }
    }

    class OrderFooterHolder extends RecyclerView.ViewHolder {
        TextView tvTotalNum, tvTotalPrice, tvTotalText;
        TextView tvRebuy, tvTrace, tvConfirm, tvCheckout, tv_cancle_order, tvGotoComment,
                tvSnatchDetails, tvDeleteOrder;

        public OrderFooterHolder(View itemView) {
            super(itemView);
            tvTotalText = itemView.findViewById(R.id.tv_total_text);
            tvTotalNum = itemView.findViewById(R.id.tv_total_num);
            tvTotalPrice = itemView.findViewById(R.id.tv_total);
            tvRebuy = itemView.findViewById(R.id.tv_rebuy);
            tvTrace = itemView.findViewById(R.id.tv_trace);
            tvConfirm = itemView.findViewById(R.id.tv_confirm);
            tvSnatchDetails = itemView.findViewById(R.id.tv_snatch_details);
            tv_cancle_order = itemView.findViewById(R.id.tv_cancle_order);
            tvCheckout = itemView.findViewById(R.id.tv_checkout);
            tvGotoComment = itemView.findViewById(R.id.tv_goto_comment);
            tvDeleteOrder = itemView.findViewById(R.id.tv_delete_order);
        }
    }

    public interface OnOrderAdapterListener {
        void onRebuy();

        void cancleOrder(int position, List<OrderBody> orderBodies);

        void onConfirmOrder(int position, List<OrderBody> orderBodies);

        void onComment(int position, List<OrderBody> orderBodies);

        void onDeleteOrder(int position, List<OrderBody> orderBodies);
    }

    public void setOnOrderAdapterListener(OnOrderAdapterListener onOrderAdapterListener) {
        this.onOrderAdapterListener = onOrderAdapterListener;
    }
}
